package com.ruoyi.gybj.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gybj.domain.MessageField;
import com.ruoyi.gybj.service.IMessageFieldService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息字段Controller
 * 
 * @author ruoyi
 * @date 2025-11-19
 */
@RestController
@RequestMapping("/message/field")
public class MessageFieldController extends BaseController
{
    @Autowired
    private IMessageFieldService messageFieldService;

    /**
     * 查询消息字段列表
     */
    @PreAuthorize("@ss.hasPermi('message:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(MessageField messageField)
    {
        startPage();
        List<MessageField> list = messageFieldService.selectMessageFieldList(messageField);
        return getDataTable(list);
    }

    /**
     * 导出消息字段列表
     */
    @PreAuthorize("@ss.hasPermi('message:field:export')")
    @Log(title = "消息字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MessageField messageField)
    {
        List<MessageField> list = messageFieldService.selectMessageFieldList(messageField);
        ExcelUtil<MessageField> util = new ExcelUtil<MessageField>(MessageField.class);
        util.exportExcel(response, list, "消息字段数据");
    }

    /**
     * 获取消息字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:field:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(messageFieldService.selectMessageFieldById(id));
    }

    /**
     * 新增消息字段
     */
    @PreAuthorize("@ss.hasPermi('message:field:add')")
    @Log(title = "消息字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MessageField messageField)
    {
        return toAjax(messageFieldService.insertMessageField(messageField));
    }

    /**
     * 修改消息字段
     */
    @PreAuthorize("@ss.hasPermi('message:field:edit')")
    @Log(title = "消息字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MessageField messageField)
    {
        return toAjax(messageFieldService.updateMessageField(messageField));
    }

    /**
     * 删除消息字段
     */
    @PreAuthorize("@ss.hasPermi('message:field:remove')")
    @Log(title = "消息字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(messageFieldService.deleteMessageFieldByIds(ids));
    }
}
